namespace AbpPlus.Extentions
{
	using System.Reflection;

	using Abp.Dependency;

	using Castle.MicroKernel.Registration;

	using MediatR;

	/// <summary>
	/// The ioc manager extention.
	/// </summary>
	public static class IocManagerExtention
	{
		/// <summary>
		/// The register assembly handler.
		/// </summary>
		/// <param name="iocManager">
		/// The ioc manager.
		/// </param>
		/// <param name="assembly">
		/// The assembly.
		/// </param>
		public static void RegisterAssemblyHandler(this IIocManager iocManager, Assembly assembly)
		{
			var container = iocManager.IocContainer;
			container.Register(Classes.FromAssembly(assembly)
				.BasedOn(typeof(IRequestHandler<,>))
				.WithServiceAllInterfaces()
				.LifestyleTransient());
			container.Register(Classes.FromAssembly(assembly)
				.BasedOn(typeof(IRequestHandler<>))
				.WithServiceAllInterfaces()
				.LifestyleTransient());
			container.Register(
				Classes.FromAssembly(assembly)
					.BasedOn(typeof(INotificationHandler<>))
					.WithServiceAllInterfaces()
					.LifestyleTransient());
		}
	}
}